﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using Microsoft.Phone.Controls;

namespace Code4WP7SDK.Controls
{
    public class BasePageArg
    {
        public object[] UseData { get; set; }
    }

    public class PageManager
    {
        static int argId = 0;
        static Object argLock = new Object();
        public static string ArgPrev = "ARGID";
        private static Dictionary<string, object> ArgDic = new Dictionary<string, object>();

        public static string PutArgs(object obj)
        {
            string id = GetArgId();     //后的arg的编号Id
            ArgDic[ArgPrev + id] = obj; //这个obj就是BasePageArg
            return id;
        }

        private static string GetArgId()
        {
            int ret = 0;
            lock (argLock)
            {
                argId++;
                ret = argId;
            }
            return ret + "";
        }

        public static object GetArgOnce(PhoneApplicationPage page)
        {
            object obj = null;
            IDictionary<string, string> queryString = page.NavigationContext.QueryString;
            if (queryString.ContainsKey(ArgPrev))
            {
                string argId = queryString[ArgPrev];        //获得编号
                if (ArgDic.ContainsKey(ArgPrev + argId))    //获得BasePageArg
                {
                    obj = ArgDic[ArgPrev + argId];
                    ArgDic.Remove(ArgPrev + argId);
                }
            }
            return obj;
        }
    }
}
